package com.example.month11.fragment2.fragments;


import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.month11.fragment2.base.BaseFragment;
import com.example.recyclerview01.R;

/**
 * 替换页面2
 */
public class Page02Fragment extends BaseFragment {
    public static final String TAG = "Page02Fragment";
    private Callback mCallback;

    public static Page02Fragment newInstance() {
        return new Page02Fragment();
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (!(context instanceof Callback)) {
            throw new IllegalArgumentException("The container activity should implement the " + TAG + "#Callback.");
        }
        mCallback = (Callback) context;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_page02, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        view.findViewById(R.id.btn_goback).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onActivityBackPressed();
            }
        });
        view.findViewById(R.id.btn_msg).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallback.showMessage("来自子页面 Page02Fragment的消息");
            }
        });
    }


    public interface Callback {
        void showMessage(String msg);
    }

}
